import 'package:flutter/material.dart';
import 'package:flutter_swiper/flutter_swiper.dart';
import 'package:mc_card/common/config.dart';
import 'package:mc_card/model/shequ/banner_model.dart';
import 'package:mc_card/widget/webview.dart';


List<BannerModel> banners;
var parentContext;
///Banner
class BannerNav extends StatelessWidget {

  BannerNav(List<BannerModel> items,BuildContext pContext){
    banners = items;
    parentContext = pContext;
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      child: _banner,
    );
  }
}

Widget get _banner {
  return Container(
    height: 160,
    color: Colors.white70,
    child: Swiper(
      itemCount: banners.length,
      autoplay: true,
      autoplayDelay: 2000,
      itemBuilder: (BuildContext context, int index) {
        return GestureDetector(
          onTap: () {
            Navigator.push(parentContext, MaterialPageRoute(builder: (context) {
              BannerModel bannerModel = banners[index];
              return WebView(
                url: bannerModel.addr,
                title: bannerModel.title,
                hideAppBar: false,
              );
            }));
          },
          child: Image.network(
            Config.getImageUrl(banners[index].pic),
            fit: BoxFit.cover,
          ),
        );
      },
      pagination: SwiperPagination(),
    ),
  );
}
